//
// Created by bxw57 on 2024/6/13.
//

#include <stdexcept>
#include <iostream>
#include "Queue.h"
template<class T>
T Queue<T>::pop() {
    if (this->top == front)
        throw std::runtime_error("Queue is empty");
    else
        return this->arr[this->front++];
}

template<class T>
void Queue<T>::push(T val) {
    if (this->top == this->cap) {
        T tmp[this->cap];
        for (int i = 0; i < this->cap; i++)
            tmp[i] = this->arr[i];
        this->cap *= 2;
        delete[] this->arr;
        this->arr = new T[this->cap];
        for (int i = 0; i < this->cap; i++)
            this->arr[i] = tmp[i];
    }
    this->arr[this->top++] = val;
}

template<class T>
void Queue<T>::show() {
    for (int i = front; i < this->top; i++)
        std::cout << this->arr[i] << " ";
    std::cout << std::endl;
}